VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "DAOProducto"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
Private mvarConnection As utilConexion 'local copy

Public Property Set Connection(ByVal vData As utilConexion)
'used when assigning an Object to the property, on the left side of a Set statement.
'Syntax: Set x.Connection = Form1
    Set mvarConnection = vData
End Property




Public Function eliminar(bean As bproducto) As Integer
On Error GoTo hnderr
Dim sql As String
sql = "SELECT * FROM proc_producto_update ('" + bean.sDescripcionCorta + "','" + bean.sDescripcionLarga + "'," + CStr(bean.nPrecio) + "," + CStr(bean.bEstado.nCodigo) + "," + CStr(bean.bCategoria.nCodigo) + "," + CStr(bean.nCodigo) + ")"
mvarConnection.Connection.Execute sql
eliminar = UtilConstantes.OPT_DATOS_ELIMINADOS

hnderr:
If Err.Number = 0 Then Exit Function
eliminar = UtilConstantes.OPT_ERROR_ENCONTRADO
Err.Clear
End Function




'---------------------------------------------------------------------------------------
' Procedure : guardarNuevo
' DateTime  : 23/06/2008 18:02
' Author    : fdamiani
' Purpose   :
'---------------------------------------------------------------------------------------
'
Public Function guardarNuevo(bean As bproducto) As Integer
On Error GoTo hnderr
Dim rst As Recordset
Dim sql As String
sql = "select * from proc_producto_insert('" + bean.sDescripcionCorta + "','" + bean.sDescripcionLarga + "',"
sql = sql + CStr(bean.nPrecio) + "," + CStr(bean.bEstado.nCodigo) + "," + CStr(bean.bCategoria.nCodigo) + "','"
sql = sql + CStr(bean.sCodBarra) + "'," + Format(bean.nComision, "########0.00") + ",'" + bean.sTipComision + "')"
Set rst = mvarConnection.Connection.Execute(sql)
guardarNuevo = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
If Err.Number = 0 Then Exit Function
guardarNuevo = UtilConstantes.OPT_ERROR_ENCONTRADO
cloneError Err
Err.Clear
End Function

'---------------------------------------------------------------------------------------
' Procedure : actualizar
' DateTime  : 23/06/2008 18:02
' Author    : fdamiani
' Purpose   :
'---------------------------------------------------------------------------------------
'
Public Function actualizar(bean As bproducto) As Integer
On Error GoTo hnderr
Dim sql As String
sql = "SELECT * FROM proc_producto_update ('" + bean.sDescripcionCorta + "','" + bean.sDescripcionLarga + "'," + CStr(bean.nPrecio) + "," + CStr(bean.bEstado.nCodigo) + "," + CStr(bean.bCategoria.nCodigo) + "," + CStr(bean.nCodigo) + ", '" + Trim(bean.sCodBarra) + "'," + CStr(bean.nComision) + ",'" + Trim(bean.sTipComision) + "')"
mvarConnection.Connection.Execute sql
actualizar = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
If Err.Number = 0 Then Exit Function
actualizar = UtilConstantes.OPT_ERROR_ENCONTRADO
cloneError Err
Err.Clear
End Function

'---------------------------------------------------------------------------------------
' Procedure : getLista
' DateTime  : 16/04/2008 23:54
' Author    : Franco
' Purpose   : Obtiene la lista de productos que coincidan con el parametro
'---------------------------------------------------------------------------------------
'
Public Function getListaPorCodigo(bean As bproducto) As Collection
On Error GoTo hnderr
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bproducto

sql = "SELECT ncodigo , sdescorta , sdeslarga , ncategoria , scategoria ,"
sql = sql + " nestado , sestado , nprecio ,scodbarra,  ntotalregistros from "
sql = sql + " proc_producto_select ( " + CStr(bean.bEstado.nCodigo) + ")"

rst.Open sql, mvarConnection.Connection, adOpenForwardOnly

While Not rst.EOF
    Set record = New bproducto
    If Not IsNull(rst.Fields("nCodigo")) Then record.nCodigo = rst.Fields("nCodigo").value
    If Not IsNull(rst.Fields("sdescorta")) Then record.sDescripcionCorta = rst.Fields("sdescorta").value
    If Not IsNull(rst.Fields("sdeslarga")) Then record.sDescripcionLarga = rst.Fields("sdeslarga").value
    If Not IsNull(rst.Fields("ncategoria")) Then record.bCategoria.nCodigo = rst.Fields("ncategoria").value
    If Not IsNull(rst.Fields("scategoria")) Then record.bCategoria.sDescripcionCorta = rst.Fields("scategoria").value
    If Not IsNull(rst.Fields("nestado")) Then record.bEstado.nCodigo = rst.Fields("nestado").value
    If Not IsNull(rst.Fields("sestado")) Then record.bEstado.sDescripcion = rst.Fields("sestado").value
    If Not IsNull(rst.Fields("nprecio")) Then record.nPrecio = rst.Fields("nprecio").value
    If Not IsNull(rst.Fields("scodbarra")) Then record.sCodBarra = rst.Fields("scodbarra").value
    
    rst.MoveNext
    list.Add record
Wend
Set getListaPorCodigo = list

hnderr:
If Err.Number = 0 Then Exit Function
Err.Clear
End Function



'---------------------------------------------------------------------------------------
' Procedure : listar
' DateTime  : 16/04/2008 23:54
' Author    : Franco
' Purpose   : Obtiene la lista de productos que coincidan con el parametro
'---------------------------------------------------------------------------------------
'
Public Function getListaPorParametros(bean As bproducto) As Collection
On Error GoTo hnderr
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bproducto

sql = "SELECT ncodigo , sdescorta , sdeslarga , ncategoria , scategoria ,"
sql = sql + " nestado , sestado , nprecio ,scodbarra,  ncomision, stipcomision from "
sql = sql + " proc_producto_select ( " + CStr(bean.nCodigo) + ",'" + CStr(Trim(bean.sDescripcionCorta)) + "',"
If Not bean.bCategoria Is Nothing Then sql = sql + CStr(bean.bCategoria.nCodigo) Else sql = sql + "0"
sql = sql + "," + CStr(bean.bEstado.nCodigo)
sql = sql + ");"
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly

While Not rst.EOF
    Set record = New bproducto
    If Not IsNull(rst.Fields("nCodigo")) Then record.nCodigo = rst.Fields("nCodigo").value
    If Not IsNull(rst.Fields("sdescorta")) Then record.sDescripcionCorta = rst.Fields("sdescorta").value
    If Not IsNull(rst.Fields("sdeslarga")) Then record.sDescripcionLarga = rst.Fields("sdeslarga").value
    If Not IsNull(rst.Fields("ncategoria")) Then record.bCategoria.nCodigo = rst.Fields("ncategoria").value
    If Not IsNull(rst.Fields("scategoria")) Then record.bCategoria.sDescripcionCorta = rst.Fields("scategoria").value
    If Not IsNull(rst.Fields("nestado")) Then record.bEstado.nCodigo = rst.Fields("nestado").value
    If Not IsNull(rst.Fields("sestado")) Then record.bEstado.sDescripcion = rst.Fields("sestado").value
    If Not IsNull(rst.Fields("nprecio")) Then record.nPrecio = rst.Fields("nprecio").value
    If Not IsNull(rst.Fields("scodbarra")) Then record.sCodBarra = rst.Fields("scodbarra").value
    If Not IsNull(rst.Fields("ncomision")) Then record.nComision = rst.Fields("ncomision").value
    If Not IsNull(rst.Fields("stipcomision")) Then record.sTipComision = rst.Fields("stipcomision").value
    
    rst.MoveNext
    list.Add record
Wend
Set getListaPorParametros = list

hnderr:
If Err.Number = 0 Then Exit Function
Err.Clear
End Function
